package action.wxmember;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.ServletActionContext;

import security.MySecurityContextHandle;
import service.interf.IWxMember;
import action.common.MyBaseAction;

import com.opensymphony.xwork2.ModelDriven;

import dao.pojo.WxMember;

public class WxMemberBrowAction extends MyBaseAction<WxMember> implements
		ModelDriven<WxMember> {

	private static final long serialVersionUID = 1L;
	private IWxMember wxMember;
	private Long uid;

	public Long getUid() {
		return uid;
	}

	public void setUid(Long uid) {
		this.uid = uid;
	}

	public void setWxMember(IWxMember wxMember) {
		this.wxMember = wxMember;
	}

	public WxMemberBrowAction() {
		super(WxMember.class);
	}

	public WxMember getModel() {
		return model;
	}

	/**
	 * 获取当前登录用户
	 */
	public void getcurmember() {
		String r = "1";
		try {
			Long userId = MySecurityContextHandle.getUserId();
			r = wxMember.init_add_point(userId);
		} catch (Exception e) {
			r = errorHandle.handleErr(e);
		}
		servletHandle.writeToClient1(ServletActionContext.getResponse(), r);
	}

	/**
	 * 获取所有用户
	 */
	public void getmemberlist() {
		String r = "1";
		try {
			String[] pNames = new String[] { "isAuth" };
			Object[] pValues = new Object[] { true };
			String[] relation = new String[] { "=" };
			if (!StringUtils.isEmpty(model.getNickName())) {
				pNames = new String[] { "isAuth", "nickName" };
				pValues = new Object[] { true, "%" + model.getNickName() + "%" };
				relation = new String[] { "=", "like" };
			}
			r = wxMember.findByProperty("WxMember", "*", "json", true, pNames,
					pValues, null, relation, model.getPage(), model.getRows());
		} catch (Exception e) {
			r = errorHandle.handleErr(e);
		}
		servletHandle.writeToClient(ServletActionContext.getResponse(), r);
	}

	/**
	 * 获取单个用户
	 */
	public void getmbyid() {
		String r = "1";
		try {
			r = wxMember.findById("WxMember", "*", "json", "userId", model
					.getUserId());
		} catch (Exception e) {
			r = errorHandle.handleErr(e);
		}
		servletHandle.writeToClient(ServletActionContext.getResponse(), r);
	}
}